// components/formInput/formInput.js
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    valueTxt:{
      type: String,
      value: ''
    },
    key: {
      type: String,
      value: ''
    },
    inputtype:{
      type: String,
      value: ''
    },
    placeholder:{
      type: String,
      value: ''
    },
    maxlength:{
      type: String,
      value: '-1'
    },
  },

  /**
   * 组件的初始数据
   */
  data: {
    isClose: false,
    closeShow: false
  },
  /**
   * 组件的方法列表
   */
  methods: {
    valueTransfer(){ //监听父组件输入框是否有值
      this.setData({
        closeShow: true
      })
    },
    close(){ //一键清除
      this.data.isClose = true
      setTimeout(()=>{
        this.setData({
          valueTxt: ''
        }, ()=>{
          this.properties.valueTxt = ''
          this.setData({
            closeShow: false,
          })
          this.triggerEvent('value',{
            key: this.data.key,
            value: ''
          })
        })
      },100)
      console.log(this.properties.valueTxt)
    },
    bindFrom(e){
      console.log(this.properties.name+"---" + this.properties.valueTxt)
      if(this.data.isClose){
        this.data.isClose = false
        // return
      }
      this.triggerEvent('value',{
        key: this.data.key,
        value: e.detail.value
      })
      if(this.properties.valueTxt.length>0){
        console.log('-----')
        this.setData({
          closeShow: true
        })
      }else{
        console.log('+++++')
        this.setData({
          closeShow: false
        })
      }
    },
    bindfocus(){ //聚焦时
      console.log('this.properties.valueTxt.length',this.properties.valueTxt.length)
      if(this.properties.valueTxt.length>0){
        this.setData({
          closeShow: true
        })
      }
    },
    bindblur(){ //失去焦点
      this.setData({
        closeShow: false
      })
    },
  }
})
